﻿#include "park.h"
Car *pop(struct stack *s)
{
	Car *to_return = s->top;
	ASSERT_ABORT(s->top > 0, "停车场已空");
	s->count--;
	s->top = s->top->next;
	return to_return;
}
bool push(struct stack *s, Car *p_car)
{
	ASSERT_ABORT(p_car, "无车辆进入");
	ASSERT_ABORT(s->count < capacity, "停车场已满");
	for (Car* p = s->top; p; p = p->next) {
		if (strcmp(p->name, p_car->name))
			continue;
		printf("%s已存在\n",p->name);
		return false;
	}
	p_car->next = s->top;
	s->top = p_car;
	s->count++;
	return true;
}

int enque(Car *p)
{
	if (p == NULL)
		return false;
	if (lane.first == NULL && lane.last == NULL)
	{
		p->next = NULL;
		lane.first = p;
		lane.last = p;
		return true;
	}
	lane.last->next = p;
	lane.last = lane.last->next;
	return true;
}
Car *deque(void)
{
	Car *ret = lane.first;
	if(ret)
		lane.first = lane.first->next;
	return ret;
}